home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: Large Number Arithmetic
- Date: 29 Feb 1996 19:04:07 GMT
- Organization: OpenVision
- Message-ID: <4h4tb7$qlp@spanky.pls.ov.com>
- References: <4gu61k$52@vnetnews.value.net>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article 52@vnetnews.value.net, Adonis Ioannou <adonis@value.net> writes:
- >Your help will be greatly appreciated...
- >
- >I am trying to create a simple calculator, which supports + - / * %, using the
- >following input from the command line:-
- >
- > nnn + nnn where nnn is an integer up to 40 digits long.
- >
- >The output should also be of the same format(no scientific notations)
- >
- >I have tried to read the values using
- >
- > scanf("%Lf", &x) where x is a long double(so that I can store these
- > large numbers),
- >but after I enter more than 20 digits, I start to lose some accuracy.
- >
- >I also tried to read the input into character arrays, and then convert the string
- >using _atold(), but had the same problem. Can anyone give me any clues or suggestions?
- >
- >I am using VisualC++ 1.52, under WIN95.
- >
- >Here is an example of what I mean:-
- >
- >#include <stdio.h>
- >#include <stdlib.h>
- >
- >void main(void)
- >{
- > long double x;
- >
- > scanf("%Lf", &x);
- > printf("%Lf", x);
- >}
- >
- >If I enter 12345678901234567890 I get the same result.
- >If I enter 123456789012345678901 I get 123456789012345678904
- >
- >Thanks
- >
-
-
-
- It doesn't matter what machine you are on, a double on a given machine can
- only hold so many significant digits. If you try to enter more significant
- digits, the machine has no way to store them. If you wish to use larger
- numbers of digits, then you must emulate larger data storage types than the
- machine can handle. Emulate means that now, your program is the calculator
- and not the machine.
-
- Fletcher.Glenn@ov.com
-
-